﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace DBLayer
{
    public class GetMax
    {


        // get the biggest id according to the query 
        public static int GetMaxId(String Query)
        {
            int id = -1;
            SqlConnection conn = DBConnection.getConnection().getSQLConnection();
            SqlDataReader reader;
            SqlCommand command = new SqlCommand(Query,conn);

            try
            {
                if (conn.State == System.Data.ConnectionState.Closed)
                 
                    conn.Open(); 
                
                 
                reader = command.ExecuteReader();
                if (reader.Read())
                {
                    id = (int)reader[0];
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("error with getmax trololo");
                Console.WriteLine(e.Message);
            }
            finally
            {
               // conn.Close();
            }
            return id;
        }

        //get  max pass id
            public static int GetMaxId()
            {
                int id = -1;
                SqlConnection conn = DBConnection.getConnection().getSQLConnection();
                SqlDataReader reader;
                SqlCommand command = new SqlCommand("use dm77_1 select max(id) from TaxiRequests", conn);

                try
                {
                    if (conn.State == System.Data.ConnectionState.Closed)

                        conn.Open();


                    reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        id = (int)reader[0];
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine("error with getmax trololo");
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    conn.Close();
                }
                return id;
            }
        


    }
}
